<%@page import="javax.swing.text.StyleContext.SmallAttributeSet"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%!
	class UploadList{
		int id;
		int userid;
		String username;
		String name;
		String datetime;
		String detail;
		boolean hidden;
		int count;
		String file;
	}
%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>资源搜索|银光云-为银光字幕组提供最优质的云存储服务 - Powered by 金鸡独立</title>
<%
	request.setCharacterEncoding("utf-8"); 
	String keyword=request.getParameter("keyword");
	UploadList[] ul=null;
	Class.forName("com.mysql.jdbc.Driver");
	Connection con=DriverManager.getConnection((String) application.getAttribute("dburl"),(String) application.getAttribute("username"),(String) application.getAttribute("password"));
 	Statement s=con.createStatement();
 	Statement s1=con.createStatement();
	String sqls1="SELECT * FROM data WHERE (name LIKE '"+keyword+"' OR name LIKE '%"+keyword+"' OR name LIKE '"+keyword+"%' OR name LIKE '%"+keyword+"%') AND hidden=FALSE";
	ResultSet rs=s.executeQuery(sqls1);
	rs.last();
	int len=rs.getRow();
	rs.beforeFirst();
	if(len>0){
		ul=new UploadList[len];
		for(int i=0;i<len;++i) ul[i]=new UploadList();
		rs.next();
		for(int i=0;i<len;++i){
			ul[i].id=rs.getInt(1);
			ul[i].userid=rs.getInt(2);
			ul[i].name=rs.getString(3);
			if(ul[i].name.length()>15) ul[i].name=ul[i].name.substring(0,16)+"……";
			ul[i].datetime=rs.getString(4);
			ul[i].detail=rs.getString(5);
			if(ul[i].detail.length()>15) ul[i].detail=ul[i].detail.substring(0,16)+"……";
			ul[i].hidden=rs.getBoolean(6);
			ul[i].count=rs.getInt(7);
			ul[i].file=rs.getString(8);
			if(ul[i].file.length()>15) ul[i].file=ul[i].file.substring(0,16)+"……";
			rs.next();
			String sqls2="SELECT name FROM user WHERE id="+ul[i].userid;
			ResultSet rs1=s1.executeQuery(sqls2);
			if(rs1==null){
				out.println("致命错误-0006：无法在数据库中找到username！请联系QQ2276768747以解决问题。");
				return ;
			}
			rs1.next();
			ul[i].username=rs1.getString(1);
		}
		for(int i=0;i<len;++i){
			
		}
	}
%>
</head>
<body>
<center>
<h1><font color="red">银光字幕组专属云-搜索结果</font></h1>
<table>
	<tr>
		<td><a href="/SilverCould/index.jsp">返回主页</a></td>
		<td>
			<form action="/SilverCould/page/search.jsp" method="get">
				<input type="text" id="keyword" name="keyword" style="width: 350px">
				<input type="submit" value="搜索">
			</form>
		</td>
	</tr>
</table>
<br/>
查询内容：“<%=keyword %>”
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
查询结果：
<%if(ul!=null){ %>
共查询到<%=len %>条记录：
<br/>
<table border="1">
	<tr>
		<th>编号</th>
		<th>标题</th>
		<th>上传者</th>
		<th>上传时间</th>
		<th>简介</th>
		<th>访问次数</th>
		<th>文件名</th>
		<th>链接</th>
	</tr>
	<%
		for(int i=0;i<len;++i){
			out.println("<tr>");
			out.println("	<td>"+ul[i].id+"</td>");
			out.println("	<td>"+ul[i].name+"</td>");
			out.println("	<td>"+ul[i].username+"</td>");
			out.println("	<td>"+ul[i].datetime+"</td>");
			out.println("	<td>"+ul[i].detail+"</td>");
			out.println("	<td>"+ul[i].count+"</td>");
			out.println("	<td>"+ul[i].file+"</td>");
			out.println("	<td><a href=\"watch.jsp?id="+ul[i].id+"\">进入播放和下载页面</a></td>");
			out.println("</tr>");
		}
	%>
</table>
<%}else{ %>
<font color="red">查询无结果</font>
<%} %>
</center>
</body>
</html>